package com.kehao.leetcode.jzoffer;

import org.junit.Test;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/7 13:06
 */
public class JZSolution003 {
    public int[] countBits(int n) {
        int[] result = new int[n+1];
        result[0] = 0;
        for (int i = 1; i <= n; i++) {
            String s = Integer.toBinaryString(i);
            long count = s.chars().filter(c -> c == '1').count();
            result[i] = (int) count;
        }
        return result;
    }

    @Test
    public void test01(){
        int[] result = countBits(5);
        for (int i : result) {
            System.out.print(i+" ");
        }
    }
}
